/**
 * Created by wengms on 2016/11/20.
 */
define([angular], function () {
    return function($scope,GillionMsg,Resource,$dataSourceManager,$http){
        $scope.package={};
        $scope.removeShow=false;
        var Packages = Resource("/grule-manager/rulePackage/:id",{
            "id":"@id"
        });
        $scope.actions = {
            deletePackage:function(id){
                GillionMsg.confirm('提示信息', '是否确定删除？',
                    function (r) {
                        if (r) {
                            Packages.delete({"id":id},function(response){
                                if (response.success){
                                    GillionMsg.alert("提示", "规则包删除成功");
                                    $scope.actions.refreshTable();
                                }else{
                                    GillionMsg.alert("提示","规则包删除失败");
                                    $scope.actions.refreshTable();
                                }
                            });
                        }
                    })
            },
            search:function(){
                $dataSourceManager.dataSources['PackageDataSource'].doRequestData(1,$scope.package);
            },
            refreshTable:function(){
                $dataSourceManager.dataSources['PackageDataSource'].doRequestData();
            },
            authority:function(id,mode){
                GillionMsg.showUrl({
                    title:"授权管理",
                    data:{"targetId":id,"targetType":1,"mode":mode},
                    url: '/html2/system/permission/permissions-manager',
                    width:400,
                    height:400
                });
            },
            searchPath:function(row){
                console.log(row);
                $http({
                    method:'GET',
                    params:{
                        projectName:row.projectName,
                        projectId:row.projectId
                    },
                    url:"/grule-manager/rulePackage/getProjectPath"
                }).success(function(resp){
                    GillionMsg.alert("路径结构",resp);
                });

            }
        }
        $scope.myKeyup = function(e){
            var keycode = window.event?e.keyCode:e.which;
            if(keycode==13){
                $scope.actions.search();
            }
        };
        $scope.$watch('package.name',function(newValue,oldValue){
            if(newValue==""){
                $scope.removeShow=false;
                $scope.actions.search();
            }else if(newValue){
                $scope.removeShow=true;
            }
        });
        $scope.deleteInput=function(){
            $scope.package={name:""};
        }
    };
});